<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="订单流水号" prop="orderNumber">
        <el-input
          v-model="queryParams.orderNumber"
          placeholder="请输入订单流水号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="处理状态:" prop="checkStatus">
        <el-select v-model="queryParams.checkStatus" placeholder="请选择处理状态:" clearable>
          <el-option
            v-for="dict in dict.type.check_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="处理退货状态:" prop="returnStatus">-->
<!--        <el-select v-model="queryParams.returnStatus" placeholder="请选择处理退货状态:" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.refund_status"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['business:orderrefund:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:orderrefund:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderrefundList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="记录ID" align="center" prop="id" />-->
<!--      <el-table-column label="订单ID" align="center" prop="orderId" />-->
      <el-table-column label="订单流水号" align="center" prop="orderNumber" />
      <el-table-column label="用户" align="center" prop="nickName" />
<!--      <el-table-column label="订单项ID " align="center" prop="orderItemId" />-->
      <el-table-column label="订单支付方式" align="center" prop="payType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pay_type" :value="scope.row.payType"/>
        </template>
      </el-table-column>
      <el-table-column label="商品图片" align="center" prop="productImage" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.productImage" :width="50" :height="50"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="商品数量" align="center" prop="productNum" />-->
      <el-table-column label="商品" align="center" prop="productTitle" />
      <el-table-column label="商品简介" align="center" prop="productInfo" />
      <el-table-column label="商品价格" align="center" prop="productPrice" />
<!--      <el-table-column label="用户Id" align="center" prop="userId" />-->
      <el-table-column label="退货数量" align="center" prop="refundNum" />
      <el-table-column label="退货金额" align="center" prop="refundPrice" />
<!--      <el-table-column label="申请类型:1,仅退款,2退款退货" align="center" prop="applyType" />-->
      <el-table-column label="处理状态" align="center" prop="checkStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.check_status" :value="scope.row.checkStatus"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="处理退货状态" align="center" prop="returnStatus">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.refund_status" :value="scope.row.returnStatus"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="申请时间" align="center" prop="applyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="平台审核时间" align="center" prop="checkDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="退货时间" align="center" prop="refundTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.refundTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="图片" align="center" prop="image" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.image" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="退货原因" align="center" prop="refoundType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.refund_type" :value="scope.row.refoundType"/>
        </template>
      </el-table-column>
      <el-table-column label="其他原因" align="center" prop="buyerMsg" />
<!--      <el-table-column label="平台备注" align="center" prop="checkRemark" />-->
<!--      <el-table-column label="物流公司名称" align="center" prop="expressName" />-->
<!--      <el-table-column label="物流单号" align="center" prop="expressNo" />-->
<!--      <el-table-column label="发货时间" align="center" prop="shipTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.shipTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="收货时间" align="center" prop="receiveTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.receiveTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="收货备注" align="center" prop="receiveMessage" />-->
<!--      <el-table-column label="${comment}" align="center" prop="remark" />-->
      <el-table-column label="操作" align="center"  fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="checkhandleUpdate(scope.row)"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:orderrefund:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改退货售后对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
<!--        <el-form-item label="订单ID" prop="orderId">-->
<!--          <el-input v-model="form.orderId" placeholder="请输入订单ID" />-->
<!--        </el-form-item>-->
        <el-row>
          <el-col :span="12">
            <el-form-item label="订单流水号" prop="orderNumber">
              <el-input v-model="form.orderNumber" placeholder="请输入订单流水号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户" prop="nickName">
              <el-input v-model="form.nickName" placeholder="请输入用户" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="商品名称" prop="productTitle">
              <el-input v-model="form.productTitle" placeholder="请输入商品名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="商品图片" prop="productImage">
          <image-upload v-model="form.productImage"/>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="退货数量" prop="refundNum">
              <el-input v-model="form.refundNum" placeholder="请输入退货数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="退货金额" prop="refundPrice">
              <el-input v-model="form.refundPrice" placeholder="请输入退货金额" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="处理状态" prop="checkStatus">
              <el-select v-model="form.checkStatus" placeholder="请选择处理状态">
                <el-option
                  v-for="dict in dict.type.check_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="申请时间" prop="applyTime">
              <el-date-picker clearable
                              v-model="form.applyTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择申请时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="平台审核时间" prop="checkDate">
              <el-date-picker clearable
                              v-model="form.checkDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择平台审核时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>




        <el-form-item label="图片" prop="image">
          <image-upload v-model="form.image"/>
        </el-form-item>
        <el-form-item label="售后原因" prop="refoundType">
          <el-select v-model="form.refoundType" placeholder="请选择退款原因">
            <el-option
              v-for="dict in dict.type.refound_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="其他原因" prop="buyerMsg">
          <el-input v-model="form.buyerMsg"  type="textarea" placeholder="请输入其他原因" />
        </el-form-item>
        <el-form-item label="平台备注" prop="checkRemark">
          <editor v-model="form.checkRemark" :height="300" />
        </el-form-item>
<!--        <el-row>-->
<!--          <el-col :span="12">-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--          </el-col>-->
<!--        </el-row>-->
<!--        <el-form-item label="订单项ID " prop="orderItemId">-->
<!--          <el-input v-model="form.orderItemId" placeholder="请输入订单项ID " />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="用户Id" prop="userId">-->
<!--          <el-input v-model="form.userId" placeholder="请输入用户Id" />-->
<!--        </el-form-item>-->



<!--        <el-form-item label="处理退货状态:" prop="returnStatus">-->
<!--          <el-select v-model="form.returnStatus" placeholder="请选择处理退货状态">-->
<!--            <el-option-->
<!--              v-for="dict in dict.type.refund_status"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="dict.value"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->





      </el-form>
      <div slot="footer" class="dialog-footer">
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <el-dialog :title="title" :visible.sync="checkopen" width="800px" append-to-body>
      <el-form ref="checkform" :model="checkform" :rules="checkRules" label-width="120px">
        <el-form-item label="审核状态" prop="checkStatus"  >
          <el-select v-model="checkform.checkStatus" placeholder="请选择审核状态">
            <el-option
              label="审核通过"
              value="2"
            ></el-option>
            <el-option
              label="审核不通过"
              value="3"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核备注" prop="checkRemark" >
          <editor v-model="checkform.checkRemark" :height="300" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="checksubmitForm">确 定</el-button>
        <el-button @click="checkcancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrderrefund, getOrderrefund, delOrderrefund, addOrderrefund, updateOrderrefund,checkXx } from "@/api/business/orderrefund";

export default {
  name: "Orderrefund",
  dicts: ['check_status', 'refund_status','refound_type','pay_type'],
  data() {
    return {
      checkopen:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 退货售后表格数据
      orderrefundList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        orderNumber: null,
        orderItemId: null,
        payType: null,
        userId: null,
        refundNum: null,
        refundPrice: null,
        applyType: null,
        checkStatus: null,
        returnStatus: null,
        applyTime: null,
        checkDate: null,
        refundTime: null,
        image: null,
        refoundType: null,
        buyerMsg: null,
        checkRemark: null,
        expressName: null,
        expressNo: null,
        shipTime: null,
        receiveTime: null,
        receiveMessage: null,
      },
      // 表单参数
      form: {},
      checkform:{
        id: null,
        checkStatus: null,
        checkRemark: null,

      },
      // 表单校验
      rules: {
      },
      checkRules : {
        checkStatus: [
          { required: true, message: "请选择审核状态", trigger: "blur" }
        ],
        checkRemark: [
          { required: true, message: "请输入审核备注", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询退货售后列表 */
    getList() {
      this.loading = true;
      listOrderrefund(this.queryParams).then(response => {
        this.orderrefundList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    checkcancel(){
      this.checkopen = false;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderId: null,
        orderNumber: null,
        orderItemId: null,
        payType: null,
        userId: null,
        refundNum: null,
        refundPrice: null,
        applyType: null,
        checkStatus: null,
        returnStatus: null,
        applyTime: null,
        checkDate: null,
        refundTime: null,
        image: null,
        refoundType: null,
        buyerMsg: null,
        checkRemark: null,
        expressName: null,
        expressNo: null,
        shipTime: null,
        receiveTime: null,
        receiveMessage: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加退货售后";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrderrefund(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看退货售后";
      });
    },
    checkhandleUpdate(row){
      this.checkopen =true
      this.checkform.id=row.id
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrderrefund(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrderrefund(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    checksubmitForm(){
      this.$refs["checkform"].validate(valid => {
        if (valid) {
          if (this.checkform.id != null) {
            checkXx(this.checkform).then(response => {
              this.$modal.msgSuccess("操作成功");
              this.checkform.checkRemark="";
               this.checkopen = false;
              this.getList();
            });
          }
        }
      });

    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除退货售后编号为"' + ids + '"的数据项？').then(function() {
        return delOrderrefund(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/orderrefund/export', {
        ...this.queryParams
      }, `orderrefund_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
